// axios 传参 params，data
// params的对象参数名和值，axios源码会把参数和值，拼接在url?后面给后台（query查询）
// data的对象参数名和值，axios源码会把参数和值，拼接在请求体里（body参数）
import request from '../utils/request'

// 获取轮播图数据
const getBannersAPI = () => request.get('/home/swiper')

// 获取租房小组数据，把地址位置传给后台
const getTenementGroupsAPI = (area) =>
  request.get('/home/groups', {
    params: {
      area,
    },
  })

// 获取最新资讯数据
const getNewsAPI = (area) =>
  request.get('/home/news', {
    params: {
      area,
    },
  })

// 根据城市名称查询该城市信息
const getInfoAPI = (name) =>
  request.get('/area/info', {
    params: {
      name,
    },
  })

// 获取城市列表数据, 获取哪一级的城市，level等于1 表示获取所有城市数据，level等于2 表示城市下区的数据
const getCityListAPI = (level) =>
  request.get('/area/city', {
    params: {
      level,
    },
  })

// 获取热门城市
const getHotCityListAPI = () => request.get('/area/hot')

// 获取房源数据 /area/map
const getMapDataAPI = (id) =>
  request.get('/area/map', {
    params: {
      id,
    },
  })

// 获取小区房源数据
const getHousesListAPI = (cityId) =>
  request.get('/houses', {
    params: {
      cityId,
    },
  })

// 根据id查询房屋详情
const getHouseDetailsAPI = (id) => request.get('/houses/' + id)

// 登录
const loginAPI = (data) => request.post('/user/login', data)
// 退出登录
const logOutAPI = () => request.post('/user/logout')

// 获取用户信息
const getUserInfoAPI = () => request.get('/user')

// 更新用户信息 avatar gender nickname phone
const updateUserAPI = (data) => request.patch('/user', data)

// 注册
const regAPI = (data) => request.post('/user/registered', data)

// 点击收藏
const favoritesAPI = (id) => request.post('/user/favorites/' + id)

// 查看收藏列表
const getFavoritesAPI = () => request.get('/user/favorites')

// 查看房屋是否收藏 返回 true false
const isFavoritesAPI = (id) => request.get('/user/favorites/' + id)

// 删除收藏
const delFavoritesAPI = (id) => request.delete('/user/favorites/' + id)

// 获取已发布房源列表
const getPublicHouseListAPI = () => request.get('/user/houses')

// 发布房源
const publicHouseListAPI = (data) => request.post('/user/houses', data)

export {
  getBannersAPI,
  getTenementGroupsAPI,
  getNewsAPI,
  getInfoAPI,
  getCityListAPI,
  getHotCityListAPI,
  getMapDataAPI,
  getHousesListAPI,
  getHouseDetailsAPI,
  loginAPI,
  getUserInfoAPI,
  updateUserAPI,
  logOutAPI,
  regAPI,
  favoritesAPI,
  getFavoritesAPI,
  delFavoritesAPI,
  isFavoritesAPI,
  getPublicHouseListAPI,
  publicHouseListAPI,
}
